package com.test.burnincash.aaahpoppomelo.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.EditText;

import com.test.burnincash.R;
import com.test.burnincash.aaahpoppomelo.base.BaseActivity_hpoppomelo;
import com.test.burnincash.aaahpoppomelo.bean.OrderItem_hpoppomelo;
import com.test.burnincash.aaahpoppomelo.bean.UserData_hpoppomelo;
import com.test.burnincash.util_burnin.StringUtil_burnin;

public class EditItemActivity_hpoppomelo extends BaseActivity_hpoppomelo {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_item_hpoppomelo);
        init();
    }

    private void init(){

        setBackBtn_burnin(findViewById(R.id.activity_edit_item_ib_back));

        EditText noEt = findViewById(R.id.activity_edit_item_et_no);
        EditText itemNameEt = findViewById(R.id.activity_edit_item_et_item_name);
        EditText priceEt = findViewById(R.id.activity_edit_item_et_price);
        EditText quantityEt = findViewById(R.id.activity_edit_item_et_quantity);

        noEt.setText(String.valueOf(OrderItem_hpoppomelo.optionItem.getNo()));
        itemNameEt.setText(OrderItem_hpoppomelo.optionItem.getItemName());
        priceEt.setText(String.valueOf(OrderItem_hpoppomelo.optionItem.getPrice()));
        quantityEt.setText(String.valueOf(OrderItem_hpoppomelo.optionItem.getQuantity()));

        findViewById(R.id.activity_edit_item_btn_confirm).setOnClickListener(v -> {
            if (!TextUtils.isEmpty(noEt.getText())) OrderItem_hpoppomelo.optionItem.setNo(StringUtil_burnin.safeParseInt(noEt.getText().toString()));
            if (!TextUtils.isEmpty(itemNameEt.getText())) OrderItem_hpoppomelo.optionItem.setItemName(itemNameEt.getText().toString());
            if (!TextUtils.isEmpty(priceEt.getText())) OrderItem_hpoppomelo.optionItem.setPrice(StringUtil_burnin.safeParseInt(priceEt.getText().toString()));
            if (!TextUtils.isEmpty(quantityEt.getText())) OrderItem_hpoppomelo.optionItem.setQuantity(StringUtil_burnin.safeParseInt(quantityEt.getText().toString()));

            UserData_hpoppomelo.getInstance().uploadData();
            finish();
        });
    }

}